package com.teach;

import com.teach.demo03.Coffee;
import com.teach.demo03.Machine01;
import com.teach.exception.ParamLtZeroException;

public class MachineTest {

	public static void main(String[] args) {
		Machine machine = new Machine01();
		machine.add(new Coffee("猫屎", 20d));
		machine.add(new Coffee("蓝山", 15d));
		machine.add(new Coffee("蓝山", 15d));
		machine.add(new Coffee("蓝山", 15d));
		System.out.println(machine);
		System.out.println("统计结果：");
		System.out.println(machine.list());
		System.out.println("设置价格");
		try {
			machine.setPrice(TypeName.Coffee, "蓝山", 16d);
		} catch (ParamLtZeroException e) {
			e.printStackTrace();
		}
		System.out.println(machine.list());
		System.out.println("投币和找零");
		try {
			machine.addMoney(100);
		} catch (ParamLtZeroException e) {
			e.printStackTrace();
		}
		System.out.println("余额："+machine.getMoney());
		System.out.println("找零："+machine.give());
		System.out.println("余额："+machine.getMoney());
		
		System.out.println("----------------------------------");

		try {
			System.out.println("购买了一杯蓝山咖啡");
			Product p = machine.buy(TypeName.Coffee, "蓝山");
			System.out.println("购买了："+p);
			System.out.println(machine.getMoney());
			System.out.println(machine);
		} catch (Exception e) {
			System.out.println("购买失败："+e.getMessage());
		}
		
		System.out.println("----------------------------------");
		try {
			machine.addMoney(30);
			System.out.println("投币成功："+machine.getMoney());
		} catch (ParamLtZeroException e) {
			e.printStackTrace();
		}
		try {
			System.out.println("购买了一杯猫屎咖啡");
			Product p = machine.buy(TypeName.Coffee, "猫屎");
			System.out.println("购买了："+p);
			System.out.println(machine.getMoney());
			System.out.println(machine);
		} catch (Exception e) {
			System.out.println("购买失败："+e.getMessage());
		}
		System.out.println("----------------------------------");
		try {
			System.out.println("购买了一杯猫屎咖啡");
			Product p = machine.buy(TypeName.Coffee, "猫屎");
			System.out.println("购买了："+p);
			System.out.println(machine.getMoney());
			System.out.println(machine);
		} catch (Exception e) {
			System.out.println("购买失败："+e.getMessage());
			System.out.println(machine.getMoney());
		}
		System.out.println("----------------------------------");
		System.out.println("找零："+machine.give());
		System.out.println("余额："+machine.getMoney());
	}
}
